<?php

set_time_limit(0);

require_once 'config.php';
require_once 'function.php';
require_once 'class/Mysql.class.php';

$db = new Mysql();

 
$sql_arr = array();
$sql_arr[] = "update Template set UrlRule = replace(UrlRule,'wondershare.com','wondershare.com.br')";
$sql_arr[] = "update Template set Style = replace(Style,'wondershare.com','wondershare.com.br')";
$sql_arr[] = "update Template set Style = replace(Style,'images.wondershare.com.br/interface/','www.wondershare.com.br/interface/')";
$sql_arr[] = "update Template set Style = replace(Style,'src=\"http://www.wondershare','src=\"http://images.wondershare')";
$sql_arr[] = "update Template set Script = replace(Script,'wondershare.com','wondershare.com.br')";
$sql_arr[] = "update Field set ProgramCode = replace(ProgramCode,'wondershare.com','wondershare.com.br')";

foreach( $sql_arr as $sql ){
	$db->query( $sql );
}


foreach( $table as $v ){
	$sql = "update Table_{$v} set url = replace(url,'wondershare.com','wondershare.com.br')";
	$db->query( $sql );
}


$replace_arr = array(
	'top_image'					=>'won_product',
	'lion_url'					=>'won_product',
	'awards_image'				=>'won_product',
	'tips'						=>'won_product',
	'ar_content'				=>'topic_article',
	'ar_image'					=>'topic_article',
	'product_icon_min'			=>'product',
	'product_icon_max'			=>'product',
	'product_box_min'			=>'product',
	'product_box_middle'		=>'product',
	'product_box_big'			=>'product',
	'product_contrast_table'	=>'product',
	'product_guide_intro'		=>'product',
	'product_guide_content'		=>'product',
	'feature_pic_min'			=>'feature',
	'feature_pic_max'			=>'feature',
	'more_feature_pic'			=>'feature',
	'block_pic_url'				=>'block',
	'block_pic'					=>'block',
	'Field_21885'				=>'Table_173',
	'Field_21888'				=>'Table_173',
	'Field_20352'				=>'Table_45',
	'Field_20360'				=>'Table_45',
	'Field_20247'				=>'Table_42',
	'Field_20741'				=>'Table_74',
	'Field_21228'				=>'Table_101',
	'Field_21237'				=>'Table_101',
	'Field_21942'				=>'Table_182',
	'Field_22219'				=>'Table_39',
	'Field_21578'				=>'Table_39',
	'Field_21579'				=>'Table_39'
);


foreach( $replace_arr as $field => $table ){
	$sql_arr = get_sql( $table, $field );
	foreach( $sql_arr as $sql ){
		$db->query( $sql );
		
		echo $sql.'<br />';
	}
	
	
	$sql_arr = get_sql_revise( $table, $field );
	foreach( $sql_arr as $sql ){
		$db->query( $sql );
	}
}


//通用替换
function get_sql( $table, $field ){
	//注：有download.wondershare.com不能替换为download.wondershare.com.br
	$sql_arr = array();
	$sql_arr[] = "update {$table} set {$field} = replace({$field},'images.wondershare.com','images.wondershare.com.br')";
	$sql_arr[] = "update {$table} set {$field} = replace({$field},'store.wondershare.com','store.wondershare.com.br')";
	$sql_arr[] = "update {$table} set {$field} = replace({$field},'www.wondershare.com','www.wondershare.com.br')";
	$sql_arr[] = "update {$table} set {$field} = replace({$field},'src=\"http://www.wondershare.com.br/','src=\"http://images.wondershare.com.br/')";
	$sql_arr[] = "update {$table} set {$field} = replace({$field},'src=\"../images/','src=\"http://images.wondershare.com.br/images/')";
	$sql_arr[] = "update {$table} set {$field} = replace({$field},'src=\"../style/','src=\"http://images.wondershare.com.br/style/')";
	$sql_arr[] = "update {$table} set {$field} = replace({$field},'www.wondershare.com.br/images/','images.wondershare.com.br/images/')";
	$sql_arr[] = "update {$table} set {$field} = replace({$field},'addthis:url=\"http://www.wondershare.com','addthis:url=\"http://www.wondershare.com.br')";
	$sql_arr[] = "update {$table} set {$field} = replace({$field},'images.wondershare.com.br/interface/','www.wondershare.com.br/interface/')";//调用接口文件，接口文件在www下
	return $sql_arr;
}

//地址修正
function get_sql_revise( $table, $field ){
	$sql_arr = array();
	$sql_arr[] = "update {$table} set {$field} = replace({$field},'../http://','http://')";
	$sql_arr[] = "update {$table} set {$field} = replace({$field},'.html ','.html')";
	return $sql_arr;
}




